Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat : Added cidr manipulation functions to net module #1798

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

SkySingh04
Copy link

@SkySingh04 SkySingh04 commented Dec 21, 2024

1. Does this PR affect any open issues?(Y/N) and add issue references :

  • N
  • Y

Fixes : #1779

2. What is the scope of this PR (e.g. component or file name):

net module

3. Provide a description of the PR(e.g. more details, effects, motivations or doc link):

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Other

This PR introduces new networking utility functions to the kclvm runtime, enabling users to perform various CIDR-based operations. These functions provide support for parsing, validating, and deriving information from CIDR blocks, as well as checking IP inclusion. The functions are implemented in Rust and exposed to kcl via FFI.


Added Functions:

1. parse_CIDR

  • Description: Parses a given CIDR string and extracts the IP address and subnet mask.
  • Arguments:
    • cidr (string): The CIDR notation (e.g., "192.168.1.0/24").
  • Returns: A dictionary with:
    • ip: The IP address.
    • mask: The subnet mask as an integer.
  • Usage:
    parsed_cidr = net.parse_CIDR(cidr="192.168.1.0/24")
    

2. hosts_in_CIDR

  • Description: Calculates all valid host IP addresses within a given CIDR block.
  • Arguments:
    • cidr (string): The CIDR notation (e.g., "192.168.1.0/24").
  • Returns: A list of host IP addresses.
  • Usage:
    hosts = net.hosts_in_CIDR(cidr="192.168.1.0/24")
    

3. subnets_from_CIDR

  • Description: Derives subnets from a given CIDR block.
  • Arguments:
    • cidr (string): The CIDR notation (e.g., "192.168.1.0/24").
  • Returns: A list of CIDR blocks representing the subnets.
  • Usage:
    subnets = net.subnets_from_CIDR(cidr="192.168.1.0/24")
    

4. is_IP_in_CIDR

  • Description: Checks whether a given IP address is part of a specified CIDR block.
  • Arguments:
    • ip (string): The IP address to check.
    • cidr (string): The CIDR notation (e.g., "192.168.1.0/24").
  • Returns: A boolean indicating if the IP is in the CIDR block.
  • Usage:
    is_in_cidr = net.is_IP_in_CIDR(ip="192.168.1.1", cidr="192.168.1.0/24")
    

4. Are there any breaking changes?(Y/N) and describe the breaking changes(e.g. more details, motivations or doc link):

  • N
  • Y

5. Are there test cases for these changes?(Y/N) select and add more details, references or doc links:

  • Unit test
  • Integration test
  • Benchmark (add benchmark stats below)
  • Manual test (add detailed scripts or steps below)
  • Other

@Peefy Peefy requested review from He1pa and zong-zhe December 24, 2024 13:56
@Peefy Peefy added this to the v1.0 Release milestone Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add cidr manipulation functions to net module
2 participants